package com.linln.admin.business.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.linln.common.utils.ResultVoUtil;
import com.linln.common.vo.ResultVo;
import com.linln.modules.business.domain.Attendance;
import com.linln.modules.business.service.impl.AttendanceServiceImpl;
import com.linln.modules.business.vo.LateReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author Administrator
 * 考勤信息控制器
 */

@Controller
@RequestMapping("/business/attendance")
public class AttendanceController {

    @Autowired
    private AttendanceServiceImpl attendanceService;

    @RequestMapping("/index")
    public String index(Model model, Attendance attendance) {
        IPage<Attendance> page = attendanceService.getAttendances(attendance);
        model.addAttribute("list", page.getRecords());
        model.addAttribute("page", page);
        return "/business/attendance/index";
    }


    /**
     * 考勤统计图
     *
     * @return
     */
    @RequestMapping("/statisticChar")
    public String statisticChar() {
        return "/business/attendance/statisticChar";
    }

    @RequestMapping("/getStatReport/{date}")
    @ResponseBody
    public ResultVo<List<LateReport>> getStatReport(@PathVariable("date") String date) {
        ResultVo<List<LateReport>> resultVo = ResultVoUtil.success();
        List<LateReport> lateReports = attendanceService.statLateReport(date);
        resultVo.setData(lateReports);
        return resultVo;
    }


}
